#include "HtmlElement.h"
HtmlElement::HtmlElement( QObject *prent ) : AbsElement( prent)
{
    setOutObj(this);
}

HtmlElement::HtmlElement(const HtmlElement &ele ,QObject* prent) :AbsElement (ele, prent)
{
    HtmlElement e= ele;

    setEleContext(ele.getEleContext());
    setContent(ele.getText());
    getOutObj();
    setOutObj( e.getOutObj());

}



void HtmlElement::initMate()
{

}



void HtmlElement::clear()
{
    text.clear();
    eleContext.clear();
    AbsElement::clear();
}

QString HtmlElement::context()
{
    return eleString();

}

QString HtmlElement::eleString()
{
    QString html;
    html.clear();
    if(eleContext.size()==0) return text;
    for(int i =0 ;i<eleContext.size();i++){
        QString ele = eleContext[i]->toString();
        html.append(ele);
    }
    return html;
}

void HtmlElement::setContent(const QString &value)
{
    text = value;
}

void HtmlElement::setOutObj(HtmlElement * ele)
{
    outEle = ele;
}

HtmlElement *HtmlElement::getOutObj()
{
    return  outEle;
}


QString HtmlElement::getText() const
{
    return text;
}


QList<AbsElement*> HtmlElement::getEleContext() const
{
    return eleContext;
}

void HtmlElement::setEleContext(const QList<AbsElement*> &value)
{
    eleContext = value;
}

void HtmlElement::appendElement(AbsElement * ele)
{
    if(ele->metaObject()->className()==tr("Img"))
    {
        eleContext.append(ele->getOutObj());
    }
    else
    {
         eleContext.append(ele);
    }

}

void HtmlElement::alignCenter(){
    setAttrbute("align","center");
}

void HtmlElement::alignLeft(){
    setAttrbute("align","left");
}

void HtmlElement::alignRight(){
    setAttrbute("align","right");
}





void Img::setContent(const QString &value)
{

    this->setAttrbute("src",value);

}

void Img::appendElement(AbsElement *ele)
{
    ele->appendElement(this);
}
